package com.ruoyi.jwxt.controller;

import java.util.List;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.jwxt.utility.JwxtUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.jwxt.domain.PO.JwxtTeacherApplication;
import com.ruoyi.jwxt.service.IJwxtLabSchedulingService;
import com.ruoyi.jwxt.service.IJwxtTeacherApplicationService;

/**
 * 教师实验课申请登记Controller
 */
@RestController
@RequestMapping("/jwxt/tea_application")
public class JwxtTeacherApplicationController extends BaseController
{
    @Autowired
    private IJwxtTeacherApplicationService jwxtTeacherExperimentApplicationService;
    @Autowired
    private IJwxtLabSchedulingService jwxtLabSchedulingService;
    /**
     * 查询教师实验课申请登记列表
     */
    @PreAuthorize("@ss.hasPermi('jwxt:tea_application:list')")
    @GetMapping("/list")
    public TableDataInfo list(JwxtTeacherApplication jwxtTeacherExperimentApplication)
    {
        startPage();
        List<JwxtTeacherApplication> list = jwxtTeacherExperimentApplicationService.select(jwxtTeacherExperimentApplication);
        list= JwxtUtils.teaFilterByUser(list);
        return getDataTable(list);
    }

    /**
     * 导出教师实验课申请登记列表
     */
    @PreAuthorize("@ss.hasPermi('jwxt:tea_application:export')")
    @Log(title = "教师实验课申请登记", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JwxtTeacherApplication jwxtTeacherExperimentApplication)
    {
        List<JwxtTeacherApplication> list = jwxtTeacherExperimentApplicationService.select(jwxtTeacherExperimentApplication);
        list= JwxtUtils.teaFilterByUser(list);
        ExcelUtil<JwxtTeacherApplication> util = new ExcelUtil<JwxtTeacherApplication>(JwxtTeacherApplication.class);
        util.exportExcel(response, list, "教师实验课申请登记数据");
    }

    /**
     * 获取教师实验课申请登记详细信息
     */
    @PreAuthorize("@ss.hasPermi('jwxt:tea_application:query')")
    @GetMapping(value = "/{applicationId}")
    public AjaxResult getInfo(@PathVariable("applicationId") Long applicationId)
    {
        return success(jwxtTeacherExperimentApplicationService.select(applicationId));
    }

    /**
     * 新增教师实验课申请登记
     */
    @PreAuthorize("@ss.hasPermi('jwxt:tea_application:add')")
    @Log(title = "教师实验课申请登记", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JwxtTeacherApplication jwxtTeacherExperimentApplication)
    {
        return toAjax(jwxtTeacherExperimentApplicationService.insert(jwxtTeacherExperimentApplication));
    }

    /**
     * 修改教师实验课申请登记
     */
    @PreAuthorize("@ss.hasPermi('jwxt:tea_application:edit')")
    @Log(title = "教师实验课申请登记", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JwxtTeacherApplication jwxtTeacherExperimentApplication)
    {
        return toAjax(jwxtTeacherExperimentApplicationService.update(jwxtTeacherExperimentApplication));
    }

    /**
     * 删除教师实验课申请登记
     */
    @PreAuthorize("@ss.hasPermi('jwxt:tea_application:remove')")
    @Log(title = "教师实验课申请登记", businessType = BusinessType.UPDATE)
	@DeleteMapping("/{applicationIds}")
    public AjaxResult remove(@PathVariable Long[] applicationIds)
    {

        return toAjax(jwxtTeacherExperimentApplicationService.delete(applicationIds));
    }


     @Log(title = "教师实验课申请登记", businessType = BusinessType.UPDATE)
     @PreAuthorize("@ss.hasPermi('jwxt:tea_application:check')")
     @PostMapping("/pass")
     public AjaxResult pass(@RequestBody JwxtTeacherApplication tea)
     {

         return toAjax(jwxtLabSchedulingService.accept(tea));
     }

    @Log(title = "教师实验课申请登记", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('jwxt:tea_application:check')")
    @PostMapping ( "/reject")
    public AjaxResult reject(@RequestBody JwxtTeacherApplication tea)
    {
        return toAjax(jwxtLabSchedulingService.reject(tea));

    }

    @Log(title = "教师实验课申请登记", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('jwxt:tea_application:check')")
    @PostMapping("/get_validate_labs")
    public AjaxResult get_validate_labs(@RequestBody JwxtTeacherApplication
                                        tea)
    {
        return success(jwxtLabSchedulingService.getFreeLabs(tea));
    }
}
